
component output="false" extends="AbsService" accessors="true" {

	// Delegate
	property name="BlogDelegate" type="it.millemultimedia.easyBlog.delegate.BlogDelegate";

	public it.millemultimedia.easyBlog.service.BlogService function init(){
		
		return this;
	}
	
	public it.millemultimedia.easyBlog.validator.BlogValidator function getValidator(){
		
		return getBlogDelegate().getValidator();
	}
	
	public it.millemultimedia.easyBlog.model.Blog function new(){
		
		return getBlogDelegate().createInstance();
	}
	
	public it.millemultimedia.easyBlog.model.Blog function getBlog( required Any Blog ){
		
		return getBlogDelegate().read( arguments.Blog );
	}
	
	public it.millemultimedia.easyBlog.model.Blog[] function getBlogs(){
		
		return getBlogDelegate().list( arguments.Blog );
	}
	
	public boolean function blogExists( required Any Blog ){
		var result = getBlogDelegate().list( arguments.Blog );
		
		return arrayLen( result ) gt 0;
	}
	
	public void function saveBlog( required Any Blog ){
	
		transaction{
		
			try{
				
				
				if( arguments.Blog.getidBlog()  eq 0 ){
				
					this.createBlog( arguments.Blog );
				
				}else if( arguments.Blog.getIdBlog() gt 0 ){
				
					this.updateBlog( arguments.Blog );
				
				}else{
				
					throw( message="Blog id property have undefined value." );
				
				}
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function createBlog( required Any Blog ){
	
		transaction{
		
			try{
			
				getBlogDelegate().create( arguments.Blog );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function updateBlog( required Any Blog ){
	
		transaction{
		
			try{
			
				getBlogDelegate().update( arguments.Blog );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function deleteBlog( required Any Blog ){
	
		transaction{
		
			try{
			
				getBlogDelegate().delete( arguments.Blog );
				
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
							
			}
			
		}
		
	}
	
}
